<template>
  <div>
    <div style="padding: 0px 0px 20px 0px">
      <el-row>
        <el-col :span="12"
          ><div class="grid-content bg-purple">
            <el-input placeholder="请输入内容" prefix-icon="el-icon-search">
            </el-input></div
        ></el-col>
        <el-col :span="12"
          ><div class="grid-content bg-purple-light" style="text-align: right">
            <ResourecPost></ResourecPost></div
        ></el-col>
      </el-row>
    </div>
    <div></div>
    <el-table
      class="tableBox"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%;solid 2px #2e354a"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="id" label="编号" width="50" align="center">
      </el-table-column>
      <el-table-column prop="rname" label="名称" align="center">
      </el-table-column>
      <el-table-column prop="url" label="组件" align="center">
      </el-table-column>
      <el-table-column label="菜单/资源" align="center">
      <template slot-scope="scope">{{ scope.row.pid?'资源':'菜单' }}</template>
      </el-table-column>
      <el-table-column label="接口权限/页面" align="center">
      <template slot-scope="scope">{{ scope.row.type==1?'接口权限': '页面' }}</template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-button @click="toggleSelection([tableData[1], tableData[2]])"
        >切换第二、第三行的选中状态</el-button
      >
      <el-button @click="toggleSelection()">取消选择</el-button>
    </div>

    <div>
      <el-pagination
        background
        layout="prev, pager, next"
        :page-count="page"
        :page-size="page_size"
        :total="total"
        @current-change="pageRole"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import ResourecPost from "@/components/ResourcePost.vue";
export default {
  data() {
    return {
      tableData: [],
      multipleSelection: [],
      page: 1,
      page_size: 5,
      total: 0,
    };
  },

  components: {
    ResourecPost,
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 获取角色
    roleDataGet(num) {
      this.axios
        .get("/admin/rbacm/get/resource", {
          params: { page: num, page_size: this.page_size },
        })
        .then((res) => {
          console.log("获取角色的响应:", res);
          this.tableData = res.data.data.items;
          this.total = res.data.data.total;
        });
    },
    // 分页
    pageRole(page) {
      console.log(page);
      this.roleDataGet(page);
    },
  },
  mounted() {
    this.roleDataGet(this.page);
  },
};
</script>
<style scoped>
.tableBox {
  border: solid 2px #f3f4f7;
}
</style>